package org.accp.controller;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.util.StringUtil;
import org.accp.dao.*;
import org.accp.pojo.*;
import org.accp.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/bli")
@CrossOrigin("*")


public class BilController {
    @Autowired
    private bliDao bliDao;
    @RequestMapping("/search")
    @ResponseBody
    public List<Bli> search() throws Exception{
        return bliDao.getAll();
    }
    @RequestMapping("/list")
    @ResponseBody
    public ResponseResult<List<Bli>> list(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int limit, Bli condition) throws Exception {
        Map<String,Object> map = new HashMap<>();
        Page<Bli> pager = PageHelper.startPage(page, limit);
        List<Bli> list = bliDao.getConditionList(condition);
        return new ResponseResult(pager.getTotal(),list);
    }
    @RequestMapping("/add")
    @ResponseBody
    public ResponseResult add(Bli bli) throws Exception{
        bliDao.add(bli);
        return ResponseResult.createSuccessResult();
    }
    @RequestMapping("/adds")
    @ResponseBody
    public ResponseResult adds(Bli bli) throws Exception{
        bliDao.adds(bli);
        return ResponseResult.createSuccessResult();
    }
    @RequestMapping("/addss")
    @ResponseBody
    public ResponseResult addss(Bli bli) throws Exception{
        bliDao.addss(bli);
        return ResponseResult.createSuccessResult();
    }
    @RequestMapping("/updates")
    @ResponseBody
    public ResponseResult updates(Bli bli) throws Exception{
        bliDao.updates(bli);
        return ResponseResult.createSuccessResult();
    }
    @RequestMapping("/updatess")
    @ResponseBody
    public ResponseResult updatess(Bli bli) throws Exception{
        bliDao.updatess(bli);
        return ResponseResult.createSuccessResult();
    }
}
